<#include "/common/_layout.html"/>
<@layout>
	<style>

	</style>
	<div id="app">
		<el-form ref="form" :rules="rules" :model="form" label-width="100px" v-loading="loading">
			<el-row :gutter="20" style="margin: 0;">
				<el-col :span="12" :offset="5" style="padding: 0;">
					<el-form-item label="品牌名称" prop="brand_name">
						<el-input v-model.trim="form.brand_name"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>

		<el-row class="lb_form_button">
			<el-button type="primary" @click="submitForm('form')">提交</el-button>
			<el-button type="danger" @click="closeDlalog">关闭</el-button>
		</el-row>
	</div>

	<script type="text/javascript">
		var _vue = new Vue({
			el: '#app',
			data: function() {
				return {
					form: {
						brand_name: "",
					},
					rules: {
						brand_name: [{
							required: true,
							message: '请输入名称',
							trigger: 'blur'
						}, {
							trigger: 'blur',
							validator: function(rule, value, callback) {
								$.ajax({
									type: "post",
									url: "${ctx}/goodsBrand/judge",
									data: {
										"brandName": value
									},
									success: function(data) {
										if(data.result.isHas) {
											callback(new Error("类型名称已存在"));
										} else {
											callback();
										}
									}
								});
							}
						}]
					},
					loading: false
				}
			},
			methods: {
				submitForm: function(formName) {
					var params = {};
					$.each(this[formName], function(key, value) {
						params["brand." + key] = value;
					});

					FormUtils.submit(this, formName, "${ctx}/goodsBrand/add", params);
				},
				closeDlalog: function() {
					//关闭当前这个iframe的dialog
					parent._vue[window.frameElement.id].dialogVisible = false;
				}
			},
			mounted: function() {}
		});
	</script>
</@layout>